<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%--
  Created by IntelliJ IDEA.
  User: Administrator
  Date: 2025/8/1 星期五
  Time: 16:45
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>

<!DOCTYPE html>
<html>

<head>
    <base href="${pageContext.request.contextPath}/" />
    <title>襄阳蓝芯智能化办公系统</title>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <link href="static/bootstrap-3.3.5/css/bootstrap.css" rel="stylesheet">
    <link href="static/bootstrapvalidator/css/bootstrapValidator.css"
          rel="stylesheet">
    <style>
        /*定义类名为.thead-blue的样式*/
        .thead-blue {
            color: #fff;
            font-weight: bold;
            background-color: #337ab7;
        }
    </style>
    <script src="static/jquery/jquery-1.10.2.min.js"></script>
    <script src="static/bootstrap-3.3.5/js/bootstrap.js"></script>
    <script src="static/bootstrapvalidator/js/bootstrapValidator.js"></script>

</head>
<body>

<!-- 搜索 -->
<div class="panel panel-primary">
    <div class="panel-heading">
        <h4 class="panel-title">审批流程</h4>
    </div>
    <div class="panel-body">
        <form action="judge/flow/listFlow" id="seachform" method="post"
              class="form-horizontal" role="form">
            <div class="form-group">
                <div class="col-md-4">
                    <label for="flowName" class="col-md-4 control-label">流程名称</label>
                    <div class="col-md-8">
                        <input type="text" name="flowName" class="form-control"
                               placeholder="请输入流程名称" value="${flowName}">
                        <input type="hidden" name="page" id="page" value="1">
                        <input type="hidden" name="pageSize" id="pageSize" value="5">
                    </div>
                </div>
                <div class="col-md-4">
                    <label for="docType" class="col-md-4 control-label">单据类型</label>
                    <div class="col-md-8">
                        <select name="docType" class="form-control">
                            <option value="">--请选择--</option>

                            <option value="BXD" ${docType=='BXD' ? 'selected':''} >--报销申请单--</option>

                            <option value="GMD" ${docType=='GMD' ? 'selected':''} >--购买申请单--</option>

                            <option value="YDD" ${docType=='YDD' ? 'selected':''} >--移动申请单--</option>

                        </select>
                    </div>
                </div>

                <div class="col-md-4">
                    <div class="col-md-12">
                        <button type="button" onclick="searchBtn()" class="btn btn-success">搜索审批流程</button>
                        <button onclick="editFlow(0)" class="btn btn-info" type="button">添加审批流程</button>
                    </div>
                </div>
            </div>
        </form>
    </div>
</div>


<!-- 列表 -->
<div class="panel panel-primary">
    <table class="table table-bordered table-hover">
        <thead>
        <tr class="thead-blue" align="center">
            <td>流程名称</td>
            <td>单据类型</td>
            <td>流程描述</td>
            <td>流程状态</td>
            <td>操作</td>
        </tr>
        </thead>
        <tbody>
        <c:forEach items="${flowIPage.records}" var="flow">
            <tr align="center">
                <td>${flow.flowName}</td>
                <td>
                    <c:forEach items="${docTypes}" var="type">
                        ${flow.docType == type.docType ? type.docTypeName:''}
                    </c:forEach>
                </td>
                <td>
                    ${flow.info}
                </td>
                <td>
                    ${flow.state=='Y' ? '已启用':'禁用'}
                </td>
                <td>
                    <button type="button" onclick="location.href='judge/node/listNode?flowId=${flow.oid}'" class="btn btn-success btn-xs">浏览审批节点</button>


                    <c:choose>
                        <c:when test="${flow.state=='Y'}">
                            <button type="button" onclick="editFlowState(${flow.oid},'N')" class="btn btn-warning btn-xs">禁用</button>
                        </c:when>
                        <c:otherwise>
                            <button type="button" onclick="editFlowState(${flow.oid},'Y')" class="btn btn-success btn-xs">启用</button>
                        </c:otherwise>
                    </c:choose>

                    <button type="button" onclick="editFlow('${flow.oid}','${flow.flowName}','${flow.docType}','${flow.info}','${flow.state}')" class="btn btn-primary btn-xs">修改</button>

                    <button type="button" onclick="deleteFlow(${flow.oid})" class="btn btn-danger btn-xs" data-toggle="modal" data-target="#confirmModal">删除</button>
                </td>
            </tr>
        </c:forEach>
        </tbody>
    </table>
</div>

<!-- 分页 -->
<div class="input-group col-md-6 col-md-offset-3">
    <div class="row">
        <div class="btn-group">
            <button onclick="gotoPage(1,${flowIPage.size})"
                    class="btn btn-primary" type="button">首页</button>

            <c:choose>
                <c:when test="${flowIPage.current>1}">
                    <button class="btn btn-primary" onclick="gotoPage(${flowIPage.current-1},${flowIPage.size})" type="button">上一页</button>
                </c:when>
                <c:otherwise>
                    <button class="btn btn-primary disabled" type="button">上一页</button>

                </c:otherwise>
            </c:choose>




            <button class="btn btn-primary disabled" type="button">当前第${flowIPage.current}/${flowIPage.pages}页</button>

            <div class="btn-group">
                <button type="button" class="btn btn-primary dropdown-toggle"
                        data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">
                    每页显示${flowIPage.size}条 <span class="caret"></span>
                </button>
                <ul class="dropdown-menu">
                    <li><a href="javascript:gotoPage(1,5)">每页显示5条</a></li>
                    <li><a href="javascript:gotoPage(1,10)">每页显示10条</a></li>
                    <li><a href="javascript:gotoPage(1,15)">每页显示15条</a></li>
                    <li><a href="javascript:gotoPage(1,20)">每页显示20条</a></li>
                </ul>
            </div>

            <button class="btn btn-primary disabled" type="button">共${flowIPage.total}条记录</button>


            <c:choose>
                <c:when test="${flowIPage.current<flowIPage.pages}">
                    <button onclick="gotoPage(${flowIPage.current+1},${flowIPage.size})"
                            class="btn btn-primary" type="button">下一页</button>
                </c:when>
                <c:otherwise>
                    <button class="btn btn-primary disabled" type="button">下一页</button>
                </c:otherwise>
            </c:choose>

            <button
                    onclick="gotoPage(${flowIPage.pages},${flowIPage.size})"
                    class="btn btn-primary" type="button">尾页</button>
        </div>
    </div>
</div>


<div class="modal fade" id="editFlowModal" tabindex="-1" role="dialog"
     aria-labelledby="editFlowModalLabel" aria-hidden="true">
    <div class="modal-dialog">
        <div class="modal-content">
            <div class="modal-header">
                <button type="button" class="close" data-dismiss="modal"
                        aria-hidden="true">&times;</button>
                <h4 class="modal-title" id="editFlowModalLabel">编辑流程信息</h4>
            </div>
            <form action="judge/flow/editFlow" method="post" class="form-horizontal" role="form"
                  id="editFlowForm">
                <div class="modal-body">
                    <div class="row">
                        <div class="form-group col-md-12">
                            <label for="flowName" class="col-md-3 control-label">流程名称</label>
                            <div class="col-md-8">
                                <input type="hidden" name="oid" id="oid">
                                <input type="hidden" name="state" id="state" value="Y">
                                <input type="text" id="flowName" name="flowName" class="form-control" placeholder="请输入流程名称">
                            </div>
                        </div>
                    </div>

                    <div class="row">
                        <div class="form-group col-md-12">
                            <label for="docType" class="col-md-3 control-label">单据类型</label>
                            <div class="col-md-8">
                                <select id="docType" name="docType" class="form-control">
                                    <option value="">--请选择--</option>

                                    <option value="BXD">--报销申请单--</option>

                                    <option value="GMD">--购买申请单--</option>

                                    <option value="YDD">--移动申请单--</option>

                                </select>
                            </div>
                        </div>
                    </div>

                    <div class="row">
                        <div class="form-group col-md-12">
                            <label for="info" class="col-md-3 control-label">流程描述</label>
                            <div class="col-md-8">
                                <input type="text" id="info" name="info" class="form-control">
                            </div>
                        </div>
                    </div>

                </div>
                <div class="modal-footer">
                    <button type="button" class="btn btn-default" data-dismiss="modal">关闭</button>
                    <button type="submit" id="sub"  class="btn btn-primary">确认提交</button>
                </div>
            </form>
        </div>
    </div>
</div>

<br>
<br>
<br>



<!-- 模态框（Modal） -->
<div class="modal fade" id="confirmModal" tabindex="-1" role="dialog" aria-labelledby="confirmModalLabel" aria-hidden="true">
    <div class="modal-dialog">
        <div class="modal-content">
            <div class="modal-header">
                <button type="button" class="close" data-dismiss="modal" aria-hidden="true">
                    &times;
                </button>
                <h4 class="modal-title" id="confirmModalLabel">
                    提示
                </h4>
            </div>
            <div class="modal-body">
                确认删除吗？
            </div>
            <div class="modal-footer">
                <button type="button" class="btn btn-default" data-dismiss="modal">关闭
                </button>
                <button type="button" id="subconfirm" class="btn btn-primary">
                    提交更改
                </button>
            </div>
        </div>
    </div>
</div>
<script>
    $(document).ready(function(){
        $("#subconfirm").click(function(){
            deleteConfirm();
            $('#confirmModal').modal('hide');
        });
    });
</script>


<!-- 模态框（Modal） -->
<div class="modal fade" id="alertMsgModal" tabindex="-1" role="dialog" aria-labelledby="alertMsgModalLabel" aria-hidden="true">
    <div class="modal-dialog modal-xs">
        <div class="modal-content">
            <div class="modal-header">
                <button type="button" class="close" data-dismiss="modal" aria-hidden="true">
                    &times;
                </button>
                <h4 class="modal-title" id="alertMsgModalLabel">
                    提示
                </h4>
            </div>
            <div class="modal-body" id="alertmsg">
            </div>
            <div class="modal-footer">
                <button type="button" class="btn btn-default" data-dismiss="modal">关闭</button>
            </div>
        </div>
    </div>
</div>






<script type="text/javascript">
    $(document).ajaxError(function(event,xhr) {
        if(xhr.status=="403"){//没有权限
            document.location.href = xhr.getResponseHeader("url");
        }else if(xhr.status!="200"){
            //alert("服务器错误!");
            console.log("服务器错误!");
        }
    });
</script>


</body>
<script type="text/javascript">
    function gotoPage(page,pageSize){
        $("#page").val(page);
        $("#pageSize").val(pageSize);
        $("#seachform").submit();
    }
    function searchBtn(){
        $("#page").val(1);
        $("#seachform").submit();
    }


    var deleteoid;
    function deleteFlow(oid){
        deleteoid = oid;
    }
    function deleteConfirm(){
        $.get("judge/flow/deleteFlow",{"oid":deleteoid},function(s){
            if(s==true){
                document.location.href="judge/flow/listFlow";
            }else{
                $("#alertmsg").text("删除失败!当前流程下有节点不能删除!");
                $('#alertMsgModal').modal('show');
            }
        });
    }

    function editFlow(oid,flowName,docType,info,state){

        if(oid==0){
            $("#oid").val("");
            $("#flowName").val("");
            $("#info").val("");
            $("#docType").val("");
            $("#info").val("");
            $("#state").val("N");
        }else{
            $("#oid").val(oid);
            $("#flowName").val(flowName);
            $("#info").val(info);
            $("#docType").val(docType);
            $("#state").val(state);

        }
        $('#editFlowModal').modal('show');
    }

    function editFlowState(oid,state){
        $.get("judge/flow/editFlowState",{"oid":oid,"state":state},function(s){
            if(s==true){
                document.location.href="judge/flow/listFlow";
            }else{
                $("#alertmsg").text("当前流程没有节点,无法启用!");
                $('#alertMsgModal').modal('show');
            }
        });
    }

    $(document).ready(function() {

        bindValidation();//绑定验证

        $('#editFlowModal').on('hidden.bs.modal', function() {//监听modal消失
            $("#editFlowForm").data('bootstrapValidator').destroy();
            $('#editFlowForm').data('bootstrapValidator',null);
            bindValidation();//要重新绑定验证
            $("#editFlowForm")[0].reset(); //将表单中的数据也清空

        })

    });

    function bindValidation(){
        $("#editFlowForm").bootstrapValidator({
            message : 'This value is not valid',
            feedbackIcons : {/*input状态样式图片*/
                valid : 'glyphicon glyphicon-ok',
                invalid : 'glyphicon glyphicon-remove',
                validating : 'glyphicon glyphicon-refresh'
            },
            fields : {
                flowName : {
                    validators : {
                        notEmpty : {/*非空提示*/
                            message : '请输入流程名称'
                        },
                        remote:{
                            url:'judge/flow/checkFlowName',
                            delay:500,
                            type:'post',
                            message:'流程名称已经存在',
                            data:function (validator){
                                return{
                                    'oid':$("#oid").val(),
                                    'flowName':$("#flowName").val()
                                }
                            }
                        }
                    }
                },
                docType : {
                    validators : {
                        notEmpty : {/*非空提示*/
                            message : '请选择单据类型'
                        }
                    }
                }
            },
            submitHandler : function(validator,form, submitButton) {
                validator.defaultSubmit();
            }
        });
    }

</script>
</html>
